class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None

    @classmethod
    def init_with_list(cls, l):
        size = len(l)
        if size == 0:
            return None

        head = cls(l[0])
        pre = head
        for i in range(1, size):
            pre.next = cls(l[i])
            pre = pre.next
        return head

    def __str__(self):
        des = f"{str(self.val)}"
        cur = self.next
        while cur is not None:
            des += f' -> {cur.val}'
            cur = cur.next
        return des




